#pragma once

#include "ihandle.h"
#include <vector>
#include <mutex>
#include <atomic>

class IEvent;

class ClientHandle : public IHandle {
public:
    ClientHandle(IEvent* event, int sock);
    ~ClientHandle();
    void Write(const char* buf, int len);
    void Close(const std::string& log);
    bool IsClose() const;

protected:
    int GetSock() const;
    void OnIn();
    void OnOut();
    bool DoIn(std::string& log);
    bool DoOut(const char* buf, int len, std::string& log);

protected:
    std::atomic_bool mIsOK;
    int mSock;
    IEvent* mEvent;
    std::vector<char> mRecvBuf;
    std::vector<char> mSendBuf;
    std::mutex mSendMutex;
};
